/**
  **************************************************************************
  * @file     at32f403_int.c
  * @brief    main interrupt service routines.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

/* includes ------------------------------------------------------------------*/
#include "at32f403_int.h"
#include "debug.h"
/** @addtogroup AT32F403_periph_examples
  * @{
  */

/** @addtogroup 403_I2C_communication_int
  * @{
  */

/**
  * @brief  this function handles nmi exception.
  * @param  none
  * @retval none
  */
void NMI_Handler(void)
{
}

/**
  * @brief  this function handles hard fault exception.
  * @param  none
  * @retval none
  */
void HardFault_Handler(void)
{
	DEBUG_STR("hard fault\r\n");
  /* go to infinite loop when hard fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles memory manage exception.
  * @param  none
  * @retval none
  */
void MemManage_Handler(void)
{
  /* go to infinite loop when memory manage exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles bus fault exception.
  * @param  none
  * @retval none
  */
void BusFault_Handler(void)
{
  /* go to infinite loop when bus fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles usage fault exception.
  * @param  none
  * @retval none
  */
void UsageFault_Handler(void)
{
  /* go to infinite loop when usage fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles svcall exception.
  * @param  none
  * @retval none
  */
void SVC_Handler(void)
{
}

/**
  * @brief  this function handles debug monitor exception.
  * @param  none
  * @retval none
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  this function handles pendsv_handler exception.
  * @param  none
  * @retval none
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  this function handles systick handler.
  * @param  none
  * @retval none
  */
extern void current_timer_cnt(void);
extern void board_key_handle(void);
void SysTick_Handler(void)
{
	current_timer_cnt();
	board_key_handle();
}

/**
  * @brief  this function handles dma1_channel1 handler.
  * @param  none
  * @retval none
  */
void DMA1_Channel1_IRQHandler(void)
{

}

/**
  * @brief  this function handles usart2 handler.
  * @param  none
  * @retval none
  */
#include "uart.h"
void USART1_IRQHandler(void)
{
	uint16_t rxTemp = 0;
	usart_t * pUsart = get_usart();

	if (USART1->ctrl1_bit.idleien != RESET)
	{
		if(USART1->sts_bit.idlef)
		{
			rxTemp = (uint16_t)(USART1->dt);
			if (pUsart->recv_finsh_cb)
				pUsart->recv_finsh_cb();
		}
	}

	if(USART1->ctrl1_bit.rdbfien != RESET)
	{
		if(USART1->sts_bit.rdbf)
		{
			/* read one byte from the receive data register */
			rxTemp = (uint16_t)(USART1->dt);
			if(pUsart->recv_cb)
				pUsart->recv_cb(rxTemp);
		}
	}

	if(USART1->ctrl1_bit.tdbeien != RESET)
	{
		if(USART1->sts_bit.tdbe)
		{
			if (pUsart->send_cb)
				pUsart->send_cb();
		}
	}
}

/**
  * @brief  this function handles i2c event interrupt request.
  * @param  none
  * @retval none
  */
void I2C1_EVT_IRQHandler(void)
{

}

/**
  * @brief  this function handles i2c error interrupt request.
  * @param  none
  * @retval none
  */
void I2C1_ERR_IRQHandler(void)
{

}

/**
  * @brief  this function handles i2c event interrupt request.
  * @param  none
  * @retval none
  */
void I2C2_EVT_IRQHandler(void)
{

}

/**
  * @brief  this function handles i2c error interrupt request.
  * @param  none
  * @retval none
  */
void I2C2_ERR_IRQHandler(void)
{

}

/**
  * @brief  this function handles timer1 overflow handler.
  * @param  none
  * @retval none
  */
extern void board_beep_handle(void);
void TMR3_GLOBAL_IRQHandler(void)
{
	if(tmr_flag_get(TMR3, TMR_OVF_FLAG) != RESET)
	{
		tmr_flag_clear(TMR3, TMR_OVF_FLAG);
		board_beep_handle();
	}
}

/**
  * @}
  */

/**
  * @}
  */
